import copy
import re
import random
class people:
    def __init__(self, name, age):
        self.name = name
        self.age = age
        self.sports=['足球','篮球','排球']


def copy_people():
    name=['Tom','Jerry','Mike']
    new_name=copy.copy(name)
    new_name[0]='Alice'
    print(name)
    print(new_name)


def deepcopy_people():
    old_people=people('Tom', 25)
    new_people=copy.deepcopy(old_people)
    new_people.sports.append('乒乓球')
    print(old_people.sports)
    print(new_people.sports)


def re_exercise():
    #找出字符串中所有数字
    string='hello 123 45 789world'
    print(re.findall(r'\d+',string))
    #找到第一个z字符
    print(re.search(r'z.+', 'hellozworzld').group())
    print(re.match(r'f.z','frzanjeo').group())
    #0~100
    num=random.randint(0,200)
    snum=str(num)
    ret=re.match(r'[1-9]?[0-9]|100|0',snum)
    if ret:
        print('原数字是：%d'%num)
        print('匹配的数字是：%s'%ret.group())
    tels = ["13100001234", "18912344321", "10086", "18800007777"]
    for tel in tels:
        ret1=re.match(r'1[0-9]{9}[0-35-6-8-9]',tel)
        if ret1:
            print('匹配的手机号是：%s'%ret1.group())
        else:
            print('手机号:%s格式不正确'%tel)
    #替换字符串中的空格
    string='hello 123 45 789 world'
    print(re.sub(r' ','*',string))
    x_list='s90800-a89341'
    pattern=(re.match(r'(s\d*)-(a\d*)',x_list))
    print(pattern.group(1))
    print(pattern.group(2))








if __name__ == '__main__':
    copy_people()
    deepcopy_people()
    re_exercise()